/**
 * @ClassName chapter1.KP1_weiyusuan
 * @Description: TODO
 * @Author: JCC
 * @CreateTime: 2023/10/6 17:55
 */

/**
 * 位运算
 */
public class KP1_weiyusuan {
    /**
     * 打印计算机存储数据2进制位
     */
    // 左移1
    public static void print32(int num) {
        for (int i = 31; i >= 0; i--) {
            System.out.print(((num & (1 << i)) == 0) ? "0":"1");
        }
        System.out.println();
    }


    // 右移num
    public static void print32_2(int num) {
        for (int i = 31; i >= 0; i--) {
            System.out.print((((num >> i) & 1 ) == 0) ? "0":"1");
        }
        System.out.println();
    }

    public static void main0(String[] args) {
        int a = 1,b = -1;
        print32(a);
        print32(b);
        System.out.println("================================");
        print32_2(a);
        print32_2(b);
        System.out.println("--------------------------------");
        int c = Integer.MIN_VALUE,d = Integer.MAX_VALUE;
        print32(c);
        print32(d);
        System.out.println("================================");
        // >> 有符号 右移  >>> 无符号右移
        print32_2(c);
        print32_2(c>>1);
        print32_2(c>>>1);
        System.out.println("--------------------------------");
        print32_2(d);
        print32_2(d>>1);
        print32_2(d>>>1);
    }

    public static void main(String[] args) {
        print32(Integer.MIN_VALUE);
        print32(~Integer.MIN_VALUE + 1);
        System.out.println("================================");
        print32(0);
        print32(~0 + 1);
    }
}
